<?php 
define('IN_WONDERSHARE', true);
header("Content-type:text/html;charset=utf-8");
ob_start("ob_gzhandler");
require('../includes/init.php'); 
class ProductPad
{
	var $root_path = "/var/www/website/new.wondershare.com/public/";
	/**
	 * @ 构造函数,实例化adControl
	 * @ __construct
	 */
	
	public function __construct()
	{ 
	} 
	/**
	* @函数create_xml,生成pdf的xml文件
	* @param  NULL
	* @return  string
	*/
	function create_xml()
	{
		$pdf_data = $pdf_file_data =  array();
		$product_pdf_xml = file_get_contents($this->root_path.'pad_xml/product_pad_xml.xml');//得到生成pdf的xml文件的模板
		$product_id = empty($_GET['product_id'])?0:(int)$_GET['product_id'];
		$sql = "SELECT product_name,pdf_id,IF(pdf_pub_date> 0, FROM_UNIXTIME(pdf_pub_date, '%Y-%m-%d'), '') pdf_pub_date,
		pdf_language,pdf_category,File_Size_Bytes,File_Size_K,File_Size_MB,Has_Expire_Info,Expire_Count,Expire_Based_On,
		Expire_Other_Info,Char_Desc_45,Char_Desc_80,Char_Desc_250,Char_Desc_450,Char_Desc_2000,Application_Screenshot_URL,
		Affiliates_URL ,Program_System_Requirements,Keywords,Program_Type  FROM  product_pdf_xml  WHERE product_id = ".$product_id;
		$pdf_data ==  $this->_db->fetchRow($sql);

		if(empty($pdf_data))//表示为新增
		{
			$pdf_file_data = array(1=>'');
			$sql = 'SELECT p.product_name ,won_p.id,tem.Field_20047 FROM  product p 
			LEFT JOIN won_product won_p ON   won_p.won_product_id = p.product_id
			LEFT JOIN  Table_26  tem ON   won_p.id = tem.Field_20044
			WHERE  p.product_id = '.$product_id;
			$rows  = $GLOBALS['db']->getAll($sql);
			$product_name = $rows[0]['product_name'];
			 $GLOBALS['smarty']->assign('Keywords',  $rows[0]['Field_20047']);
			$GLOBALS['smarty']->assign('nums',  1);
			$GLOBALS['smarty']->assign('title',  '生成');
			$GLOBALS['smarty']->assign('form_act',  'add');
			
		}else// 表示为修改
		{
		    $sql = "SELECT file_id , web_name , file_url FROM product_pdf_file  WHERE pdf_id =  ".$pdf_data[0]['pdf_id'];
			$result = $GLOBALS['db']->query($sql);
			while($row = $GLOBALS['db']->fetch_array($result))
			{
			   $data = $this->replace_file($row['file_url'],0,'');//得到服务器文件路径
			   $row['server_file_path'] = $data['filepath'];
			   $pdf_file_data[] = $row;
			}
			$product_name = $pdf_data[0]['product_name'];
			$GLOBALS['smarty']->assign('nums',  count($pdf_file_data));
			$GLOBALS['smarty']->assign('title',  '修改');
			$GLOBALS['smarty']->assign('form_act',  'update');
		}
		//以下是语言下拉框
		$str_language = 'Abkhazian|Afar|Afrikaans|Albanian|Amharic|Arabic|Armenian|Assamese|Aymara|Azerbaijani|Bashkir|Basque|Bengali|Bhutani|Bihari|Bislama|Breton|Bulgarian|Burmese|Byelorussian|Cambodian|Catalan|Chinese|ChineseSimplified|ChineseTraditional|Corsican|Croatian|Czech|Danish|Dutch|English|Esperanto|Estonian|Faeroese|Fiji|Finnish|French|Frisian|Gaelic|Galician|Georgian|German|Greek|Greenlandic|Guarani|Gujarati|Hausa|Hebrew|Hindi|Hungarian|Icelandic|Indonesian|Interlingua|Interlingue|Inupiak|Irish|Italian|Japanese|Javanese|Kannada|Kashmiri|Kazakh|Kinyarwanda|Kirghiz|Kirundi|Korean|Kurdish|Laothian|Latin|Latvian|Lingala|Lithuanian|Macedonian|Malagasy|Malay|Malayalam|Maltese|Maori|Marathi|Moldavian|Mongolian|Nauru|Nepali|Norwegian|Occitan|Oriya|Oromo|Other|Pashto|Persian|Polish|Portuguese|Punjabi|Quechua|Rhaeto-Romance|Romanian|Russian|Samoan|Sangro|Sanskrit|Serbian|Serbo-Croatian|Sesotho|Setswana|Shona|Sindhi|Singhalese|Siswati|Slovak|Slovenian|Somali|Spanish|Sudanese|Swahili|Swedish|Tagalog|Tajik|Tamil|Tatar|Tegulu|Thai|Tibetan|Tigrinya|Tonga|Tsonga|Turkish|Turkmen|Twi|Ukrainian|Urdu|Uzbek|Vietnamese|Volapuk|Welsh|Wolof|Xhosa|Yiddish|Yoruba|Zulu';
		$language_arr = explode('|',$str_language);
		$option_language = '';
		foreach ($language_arr  AS $keys => $values)
		{
			$selected_language = '';
			if(empty($pdf_data[0]) && $values == 'English' )
			{
				$selected_language = 'selected="selected" ';
			}else
			{
				if(!empty($pdf_data[0]['pdf_language'])&& (trim($values) == trim($pdf_data[0]['pdf_language'])) )
				{
					$selected_language = 'selected="selected" ';
				}
			}
			$option_language.='<option value="'.$values.'" '.$selected_language.' >'.$values.'</option>';
		}
		//以下是pdf分类下拉框
		$str_category = 'Audio & Multimedia::Audio File Players|Audio & Multimedia::Audio File Recorders|Audio & Multimedia::CD Burners|Audio & Multimedia::CD Players|Audio & Multimedia::Multimedia Creation Tools|Audio & Multimedia::Music Composers|Audio & Multimedia::Other|Audio & Multimedia::Presentation Tools|Audio & Multimedia::Rippers & Converters|Audio & Multimedia::Speech|Audio & Multimedia::Video Tools|Business::Accounting & Finance|Business::Calculators & Converters|Business::Databases & Tools|Business::Helpdesk & Remote PC|Business::Inventory & Barcoding|Business::Investment Tools|Business::Math & Scientific Tools|Business::Office Suites & Tools|Business::Other|Business::PIMS & Calendars|Business::Project Management|Business::Vertical Market Apps|Communications::Chat & Instant Messaging|Communications::Dial Up & Connection Tools|Communications::E-Mail Clients|Communications::E-Mail List Management|Communications::Fax Tools|Communications::Newsgroup Clients|Communications::Other Comms Tools|Communications::Other E-Mail Tools|Communications::Pager Tools|Communications::Telephony|Communications::Web/Video Cams|Desktop::Clocks & Alarms|Desktop::Cursors & Fonts|Desktop::Icons|Desktop::Other|Desktop::Screen Savers: Art|Desktop::Screen Savers: Cartoons|Desktop::Screen Savers: Nature|Desktop::Screen Savers: Other|Desktop::Screen Savers: People|Desktop::Screen Savers: Science|Desktop::Screen Savers: Seasonal|Desktop::Screen Savers: Vehicles|Desktop::Themes & Wallpaper|Development::Active X|Development::Basic, VB, VB DotNet|Development::C / C\+\+ / C\#|Development::Compilers & Interpreters|Development::Components & Libraries|Development::Debugging|Development::Delphi|Development::Help Tools|Development::Install & Setup|Development::Management & Distribution|Development::Other|Development::Source Editors|Education::Computer|Education::Dictionaries|Education::Geography|Education::Kids|Education::Languages|Education::Mathematics|Education::Other|Education::Reference Tools|Education::Science|Education::Teaching & Training Tools|Games & Entertainment::Action|Games & Entertainment::Adventure & Roleplay|Games & Entertainment::Arcade|Games & Entertainment::Board|Games & Entertainment::Card|Games & Entertainment::Casino & Gambling|Games & Entertainment::Kids|Games & Entertainment::Online Gaming|Games & Entertainment::Other|Games & Entertainment::Puzzle & Word Games|Games & Entertainment::Simulation|Games & Entertainment::Sports|Games & Entertainment::Strategy & War Games|Games & Entertainment::Tools & Editors|Graphic Apps::Animation Tools|Graphic Apps::CAD|Graphic Apps::Converters & Optimizers|Graphic Apps::Editors|Graphic Apps::Font Tools|Graphic Apps::Gallery & Cataloging Tools|Graphic Apps::Icon Tools|Graphic Apps::Other|Graphic Apps::Screen Capture|Graphic Apps::Viewers|Home & Hobby::Astrology/Biorhythms/Mystic|Home & Hobby::Astronomy|Home & Hobby::Cataloging|Home & Hobby::Food & Drink|Home & Hobby::Genealogy|Home & Hobby::Health & Nutrition|Home & Hobby::Other|Home & Hobby::Personal Finance|Home & Hobby::Personal Interest|Home & Hobby::Recreation|Home & Hobby::Religion|Network & Internet::Ad Blockers|Network & Internet::Browser Tools|Network & Internet::Browsers|Network & Internet::Download Managers|Network & Internet::File Sharing/Peer to Peer|Network & Internet::FTP Clients|Network & Internet::Network Monitoring|Network & Internet::Other|Network & Internet::Remote Computing|Network & Internet::Search/Lookup Tools|Network & Internet::Terminal & Telnet Clients|Network & Internet::Timers & Time Synch|Network & Internet::Trace & Ping Tools|Security & Privacy::Access Control|Security & Privacy::Anti-Spam & Anti-Spy Tools|Security & Privacy::Anti-Virus Tools|Security & Privacy::Covert Surveillance|Security & Privacy::Encryption Tools|Security & Privacy::Other|Security & Privacy::Password Managers|Servers::Firewall & Proxy Servers|Servers::FTP Servers|Servers::Mail Servers|Servers::News Servers|Servers::Other Server Applications|Servers::Telnet Servers|Servers::Web Servers|System Utilities::Automation Tools|System Utilities::Backup & Restore|System Utilities::Benchmarking|System Utilities::Clipboard Tools|System Utilities::File & Disk Management|System Utilities::File Compression|System Utilities::Launchers & Task Managers|System Utilities::Other|System Utilities::Printer|System Utilities::Registry Tools|System Utilities::Shell Tools|System Utilities::System Maintenance|System Utilities::Text/Document Editors|Web Development::ASP & PHP|Web Development::E-Commerce|Web Development::Flash Tools|Web Development::HTML Tools|Web Development::Java & JavaScript|Web Development::Log Analysers|Web Development::Other|Web Development::Site Administration|Web Development::Wizards & Components|Web Development::XML/CSS Tools';
		$category_arr = explode('|',$str_category);
		$option_category = '';
		
		foreach ($category_arr  AS $keys => $values)
		{
			$selected_category = '';
			if(empty($pdf_data[0]) && $values == 'Audio & Multimedia::Rippers & Converters' )
			{
				$selected_category = 'selected="selected" ';
			}else
			{
				if(!empty($pdf_data[0]['pdf_category'])&& (trim($values) == trim($pdf_data[0]['pdf_category'])) )
				{
					$selected_category = 'selected="selected" ';
				}
			}
			$option_category.='<option value="'.$values.'"  '.$selected_category.' >'.$values.'</option>';
		}
		//以下是天数下拉框
		for($i=1;$i<=31;$i++)
		{
			$selected_days = '';
			if(empty($pdf_data[0]) && $i == 30 )
			{
				$selected_days = 'selected="selected" ';
			}else
			{
				if(!empty($pdf_data[0]['Expire_Count'])&& ($i == trim($pdf_data[0]['Expire_Count'])) )
				{
					$selected_days = 'selected="selected" ';
				}
			}
			$option_days .= '<option value="'.$i.'" '.$selected_days.'>'.$i.'</option>';
		}
		
		$GLOBALS['smarty']->assign('pdf_data', $pdf_data[0]);
		$GLOBALS['smarty']->assign('pdf_file_data',  $pdf_file_data);
		$GLOBALS['smarty']->assign('option_days',  $option_days);
		$GLOBALS['smarty']->assign('option_language',  $option_language);
		$GLOBALS['smarty']->assign('option_category',  $option_category);
		$GLOBALS['smarty']->assign('product_name',  $product_name);
		$GLOBALS['smarty']->assign('product_id',  $product_id);
		$GLOBALS['smarty']->display('product_pad_xml.htm'); 

	}
/**
	* @批量生成pad
	* @param  NULL
	* @return  string
	*/
	public function batch_pad()
	{
		$sql = 'SELECT product_id,product_pdf_xml.pdf_id,product_cbsid,product_name,IF(pdf_pub_date> 0, FROM_UNIXTIME(pdf_pub_date, "%Y-%m-%d"), "")
		product_pub_date,pdf_language AS product_language ,pdf_category AS product_pdf_category,File_Size_Bytes,File_Size_K,File_Size_MB,Has_Expire_Info,Expire_Count,
		Expire_Based_On,Expire_Other_Info,Keywords,Char_Desc_45,Char_Desc_80,Char_Desc_250,Char_Desc_450,Char_Desc_2000,
		Application_Screenshot_URL,Affiliates_URL,Program_System_Requirements,web_brand,Program_OS_Support,Application_Icon_URL,
		Application_Order_URL,web_brand AS web_1 ,file_url AS Application_XML_File_URL_1,Program_Type FROM product_pdf_xml LEFT JOIN   product_pdf_file ON 
		product_pdf_file.pdf_id  =  product_pdf_xml.pdf_id  WHERE web_brand IN ("wondershare") AND product_id  != 0   AND file_url LIKE  "%www.wondershare.com%"
		ORDER BY  product_id DESC  ';
		$result = $GLOBALS['db']->query($sql);
		while($row = $GLOBALS['db']->fetch_array($result))
		{
			
		    $row['Expire_Count'] = empty($row['Expire_Count'])?0:(trim($row['Expire_Count']));
		    $row['Expire_Based_On'] = empty($_POST['Expire_Based_On'])?'Uses':(trim($_POST['Expire_Based_On']));
		   
		    $this->add_update_xml($row);
		}
		echo  '<script type="text/javascript"> 
		 alert("全部生成完毕！");
		 window.location.href = "http://cms.wondershare.com/wondershare/product.php?action=productList";
	    </script>';
			
	}
	/**
	* @函数增加或者修改
	* @param  NULL
	* @return  string
	*/
	public function add_update_xml($arr_data = null)
	{
		$file_xml_str = $insert_str = $filepath = '';//要生成xml的网站地址 以|| 区分
	    if(empty($arr_data))//ws用于处理批量生成
	    {
			$nums = $_POST['web_nums'];//得到要增加网站的数量
			$post_arr = array(
			'pdf_id'=>(int)$_POST['pdf_id'],
			'product_id'=>(int)$_POST['product_id'],
			'product_name'=>trim($_POST['product_name']),
			'product_pub_date'=>trim($_POST['product_pub_date']),
			'product_language'=>(trim($_POST['product_language'])),
			'product_pdf_category'=>(trim($_POST['product_pdf_category'])),
			'Program_System_Requirements'=>trim($_POST['Program_System_Requirements']),
			'File_Size_Bytes'=>(trim($_POST['File_Size_Bytes'])),
			'File_Size_K'=>(trim($_POST['File_Size_K'])),
			'File_Size_MB'=>(trim($_POST['File_Size_MB'])),
			'Has_Expire_Info'=>(trim($_POST['Has_Expire_Info'])),
			'Expire_Count'=>empty($_POST['Expire_Count'])?0:(trim($_POST['Expire_Count'])),
			'Expire_Based_On'=>empty($_POST['Expire_Based_On'])?'Uses':(trim($_POST['Expire_Based_On'])),
			'Expire_Other_Info'=>(trim($_POST['Expire_Other_Info'])),
			'Keywords'=>(trim($_POST['Keywords'])),
			'Char_Desc_45'=>(trim($_POST['Char_Desc_45'])),
			'Char_Desc_80'=>(trim($_POST['Char_Desc_80'])),
			'Char_Desc_250'=>(trim($_POST['Char_Desc_250'])),
			'Char_Desc_450'=>(trim($_POST['Char_Desc_450'])),
			'Char_Desc_2000'=>(trim($_POST['Char_Desc_2000'])),
			'Affiliates_URL'=>(trim($_POST['Affiliates_URL'])),
			'Application_Screenshot_URL'=>(trim($_POST['Application_Screenshot_URL'])),
			'Program_Type'=>(trim($_POST['Program_Type']))
			);
	   }
	   else
	   {
	   	  $post_arr = $arr_data;
	   	  foreach ($post_arr as $key=>$value)
	   	  {
	   	  	 $post_arr[$key] = addslashes($value);
	   	  }
	   	  $nums = 1;
	   	  $_POST['Application_XML_File_URL_1'] = $post_arr['Application_XML_File_URL_1'];
	   	  $_POST['act'] = 'update';
	   	  $_POST['web_1'] = $post_arr['web_brand'];
	   }
		if($_POST['act'] == 'add')//表示为新增xml
		{
			$sql = 'INSERT INTO product_pdf_xml(product_id,product_name,pdf_pub_date,pdf_language,pdf_category,
			File_Size_Bytes,File_Size_K,File_Size_MB,Has_Expire_Info,Expire_Count,Expire_Based_On,Expire_Other_Info,Keywords,
			Char_Desc_45,Char_Desc_80,Char_Desc_250,Char_Desc_450,Char_Desc_2000,Application_Screenshot_URL,
			Affiliates_URL,update_user,update_time,add_user,add_time,Program_System_Requirements,Program_Type) VALUES ('.$post_arr['product_id'].',
			"'.$post_arr['product_name'].'","'.strtotime($post_arr['product_pub_date']).'","'.($post_arr['product_language']).'"
			,"'.($post_arr['product_pdf_category']).'","'.($post_arr['File_Size_Bytes']).'","'.($post_arr['File_Size_K']).'"
			,"'.($post_arr['File_Size_MB']).'","'.($post_arr['Has_Expire_Info']).'","'.($post_arr['Expire_Count']).'"
			,"'.($post_arr['Expire_Based_On']).'","'.($post_arr['Expire_Other_Info']).'","'.($post_arr['Keywords']).'"
			,"'.($post_arr['Char_Desc_45']).'","'.($post_arr['Char_Desc_80']).'","'.($post_arr['Char_Desc_250']).'"
			,"'.($post_arr['Char_Desc_450']).'","'.($post_arr['Char_Desc_2000']).'","'.($post_arr['Application_Screenshot_URL']).'"
			,"'.($post_arr['Affiliates_URL']).'","'.$_SESSION['AName'].'","'.$_SERVER['REQUEST_TIME'].'"
			,"'.$_SESSION['AName'].'","'.$_SERVER['REQUEST_TIME'].'","'.$post_arr['Program_System_Requirements'].'",
			"'.$post_arr['Program_Type'].'")';
			$GLOBALS['db']->query($sql);
			$pdf_id = $GLOBALS['db']->insert_id();
			$title = '增加xml';
			
			
		}elseif ($_POST['act'] == 'update')//表示为修改xml
		{
			$pdf_id = (int)$post_arr['pdf_id'];
			$sql = 'UPDATE product_pdf_xml SET pdf_pub_date = "'.strtotime($post_arr['product_pub_date']).'"
			,pdf_language = "'.($post_arr['product_language']).'"  ,pdf_category = "'.($post_arr['product_pdf_category']).'",
			File_Size_Bytes = "'.($post_arr['File_Size_Bytes']).'",File_Size_K = "'.($post_arr['File_Size_K']).'" 
			,File_Size_MB = "'.($post_arr['File_Size_MB']).'" ,Has_Expire_Info = "'.($post_arr['Has_Expire_Info']).'"
			,Expire_Count = "'.($post_arr['Expire_Count']).'" ,Expire_Based_On = "'.($post_arr['Expire_Based_On']).'"
			,Expire_Other_Info = "'.($post_arr['Expire_Other_Info']).'" ,Char_Desc_45 = "'.($post_arr['Char_Desc_45']).'" 
			,Char_Desc_80 = "'.($post_arr['Char_Desc_80']).'",Char_Desc_250 = "'.($post_arr['Char_Desc_250']).'"
			,Char_Desc_450 ="'.($post_arr['Char_Desc_450']).'" ,Char_Desc_2000 = "'.($post_arr['Char_Desc_2000']).'"
			,Application_Screenshot_URL = "'.($post_arr['Application_Screenshot_URL']).'",Affiliates_URL = "'.($post_arr['Affiliates_URL']).'"
			,update_user = "'.$_SESSION['AName'].'" ,update_time = "'.$_SERVER['REQUEST_TIME'].'" ,add_user = "'.$_SESSION['AName'].'" ,add_time = "'.$_SERVER['REQUEST_TIME'].'" 
			,Keywords = "'.($post_arr['Keywords']).'",Program_System_Requirements = "'.($post_arr['Program_System_Requirements']).'" 
			,Program_Type = "'.$post_arr['Program_Type'].'"  WHERE pdf_id = '.(INT)$post_arr['pdf_id'];
		    $GLOBALS['db']->query($sql);
		    $sql =  'DELETE FROM product_pdf_file WHERE pdf_id =  '.$pdf_id;//删除指定的xml 在库中的记录
		    $GLOBALS['db']->query($sql);
		    $title = '修改xml';
		}
	    for($i=1 ;$i<=$nums ;$i++)
		{
			$XML_File_URL = trim($_POST['Application_XML_File_URL_'.$i]);
			if(!empty($XML_File_URL))
			{
				$insert_str .= empty($insert_str)?'('.$pdf_id.',"'.$_POST['web_'.$i].'","'.trim($_POST['Application_XML_File_URL_'.$i]).'")':
				'('.$pdf_id.',"'.$_POST['web_'.$i].'","'.trim($_POST['Application_XML_File_URL_'.$i]).'"),';
				$file_xml_str .= empty($file_xml_str)?trim($_POST['Application_XML_File_URL_'.$i]):'||'.trim($_POST['Application_XML_File_URL_'.$i]);
			}	
		}
		if(!empty($insert_str))
		{
			$sql = 'INSERT INTO product_pdf_file(pdf_id,web_name,file_url) VALUES '.$insert_str;
			$GLOBALS['db']->query($sql);
		}
		
		$file_xml_rows = explode('||',$file_xml_str);
		$file_content = '';
		foreach ($file_xml_rows AS $keys=>$values)//生成xml文件
		{
			if(empty($file_content))
			{
				$file_content = file_get_contents($this->root_path.'pad_xml/product_pad_xml.xml');
				$file_content = $this->replace_template($file_content,$post_arr);//替换公共网站的模板
			}
			
			$rows = $this->replace_file($values,$post_arr['product_id'],'creat_xml');//创建相应目录以及返回文件地址，以及网站类别,以及产品url以及
			if(!empty($rows['filepath']))
			{
				if(file_exists($rows['filepath']))
				{
				 	unlink($rows['filepath']);
				}
				$file_content = str_replace('{$Application_XML_File_URL}',$values,$file_content);
				$file_content = str_replace('{$Application_Info_URL}',$rows['p_url'],$file_content);
				$file_content = str_replace('{$Application_Order_URL}',$rows['buy_url'],$file_content);
				$file_content = str_replace('&','&amp;',$file_content);
				file_put_contents($rows['filepath'],$file_content);
			}
		}
		unset($rows);unset($file_xml_rows);
		if(empty($arr_data))
		{
	        echo  '<script type="text/javascript"> 
			window.location.href="/wondershare/product_pad.php?action=create_xml&product_id='.$post_arr['product_id'].'";
			 </script>';
			exit;
		}
		
	}
  /**
	* @函数download下载
	* @param  NULL
	* @return  string
	*/
	public function download()
	{
        $upFilePath = trim($_GET['server_file_path']);
		header('Content-Type:application/octet-stream'); 
		header('accept-length:'.filesize($upFilePath));
		header('Content-Disposition:attachment;filename='.basename($upFilePath));
		readfile($upFilePath);
		ob_end_flush();

	}
	
	/**
	* @创建相应目录以及返回文件地址，以及网站类别
	* @param  NULL
	* @return  string
	*/
	public function replace_file($url,$product_id,$type = '')
	{
		$filepath = $p_url = $buy_url = '';
		if(substr_count($url,'http://www.wondershare.com')>0)//表示为http://www.wondershare.com网站
		{
			$url = str_replace('http://www.wondershare.com','',$url);
			$path_suffix = 'vhosts/wondershare.com/httpdocs';
			$filepath = $this->root_path.$path_suffix.$url;
			$web_name = 'wondershare';

		}
		elseif(substr_count($url,'http://www.aimersoft.com')>0)//表示为http://www.aimersoft.com网站
		{
			$url = str_replace('http://www.aimersoft.com','',$url);
			$path_suffix = 'vhosts/aimersoft.com/httpdocs';
			$filepath = $this->root_path.$path_suffix.$url;
			$web_name = 'aimersoft';
			
		}
		elseif(substr_count($url,'http://www.anypdftools.com')>0)//表示为http://www.anypdftools.com网站
		{
			$url = str_replace('http://www.anypdftools.com','',$url);
			$path_suffix = 'vhosts/anypdftools.com/httpdocs';
			$filepath =  $this->root_path.$path_suffix.$url;
			$web_name = 'anypdftools';
		}
		if($type == 'creat_xml')
		{
			$this->MakeDir1($this->root_path.$path_suffix.dirname($url));//循环创建目录
			$rows = $this->get_url($web_name,$product_id);
			$p_url = $rows['p_url'];$buy_url = $rows['buy_url'];
		}
		return array('filepath'=>$filepath,'buy_url'=>$buy_url,'p_url'=>$p_url);
		
	}
/**
	* @得到某个网站的产品链接 以及购买链接
	* @param  NULL
	* @return  string
	*/
	public function get_url($web_name,$product_id)
	{
		$product_tem_single = array('wondershare'=>array('tables'=>'Table_45','tem_id'=>'Field_20350','tem_default_page'=>'Field_20361'));//定义产品单页模板表数据
		$product_tem = array('wondershare'=>array('tables'=>'Table_26','tem_id'=>'Field_20044'));//定义产品模板表数据
		$buy_tem_single = array('wondershare'=>array('tables'=>'Table_74','tem_id'=>'Field_20734'));//定义产品购买单页模板表数据
		$buy_tem = array('wondershare'=>array('tables'=>'Table_39','tem_id'=>'Field_20326'));//定义产品购买模板表数据
		$p_url = $buy_url = '';
		if(!empty($product_id))
		{
			if($web_name == 'wondershare')//得到wondershare网站的产品链接以及购买链接
			{
				$sql = "SELECT tab.url  FROM  product p LEFT JOIN won_product won_p ON won_p.won_product_id = p.product_id
				 LEFT JOIN ".$product_tem[$web_name]['tables']."  tab ON won_p.id = tab.".$product_tem[$web_name]['tem_id']."
				 WHERE  p.product_id = ".$product_id;
				$p_url = $GLOBALS['db']->getOne($sql);
				if(empty($p_url))//是否存在 如果不存在在单页管理去找产品url
				{
					$sql = "SELECT tab.url  FROM  product p LEFT JOIN won_product won_p ON won_p.won_product_id = p.product_id
				 	LEFT JOIN ".$product_tem_single[$web_name]['tables']."  tab ON won_p.id = tab.".$product_tem_single[$web_name]['tem_id']." 
				 	WHERE tab.".$product_tem_single[$web_name]['tem_default_page']." = 1 AND  p.product_id = ".$product_id;
					$p_url = $GLOBALS['db']->getOne($sql);
				}
				$p_url = str_replace('/wondershare.com/httpdocs/','http://www.wondershare.com/',$p_url);
				$sql = "SELECT url FROM ".$buy_tem[$web_name]['tables']."  WHERE ".$buy_tem[$web_name]['tem_id']." = ".$product_id;
				$buy_url = $GLOBALS['db']->getOne($sql);
				if(empty($buy_url))
				{
					$sql = "SELECT url FROM ".$buy_tem_single[$web_name]['tables']." 
					 WHERE ".$buy_tem_single[$web_name]['tem_id']." = ".$product_id;
					$buy_url = $GLOBALS['db']->getOne($sql);
				}
				$buy_url = str_replace('/store.wondershare.com/httpdocs/','http://store.wondershare.com/shop/',$buy_url);
			}
		}
		return array('p_url'=>$p_url,'buy_url'=>$buy_url);
	}
	/**
	* @根据地址替换成相应的服务器地址并且创建目录
	* @param  NULL
	* @return  string
	*/
	public function replace_template($file_content,$post_arr)
	{
		$rows = array();
		if(!empty($post_arr['product_id']))//根据公共产品id得到公共产品信息
		{
			$sql = 'SELECT p.product_name,p.product_support_intro,p.product_icon_max  FROM product p  WHERE
			 p.product_id = '.$post_arr['product_id'].' LIMIT 1';
			$rows  = $GLOBALS['db']->getAll($sql);
			
			$sql = 'SELECT price,regnow_url FROM  license WHERE sub_license_id = 0 AND license_id = 11  AND product_id = '.$post_arr['product_id'].' LIMIT 1';
			$license_rows  = $GLOBALS['db']->getAll($sql);
			$rows[0]['price'] = $license_rows[0]['price'];
			$rows[0]['regnow_url'] = $license_rows[0]['regnow_url'];
			
			$sql = 'SELECT download_url,version_name,whatisnew_content FROM  version WHERE is_sale = 1  AND product_id = '.$post_arr['product_id'].' LIMIT 1';
			$license_rows  = $GLOBALS['db']->getAll($sql);
			$rows[0]['version_name'] = $license_rows[0]['version_name'];
			$rows[0]['download_url'] = $license_rows[0]['download_url'];
			$rows[0]['whatisnew_content'] = $license_rows[0]['whatisnew_content'];
		}    
		$file_content = str_replace('{$Affiliates_Regnow_Order_Page}',$rows[0]['regnow_url'],$file_content);
		$regnow_rows = explode(',',$rows[0]['regnow_url']);
	   	$regnow_rows = explode('items=',$regnow_rows[0]);
	   	$support_intro_arr   =  explode('<a',$rows[0]['product_support_intro']);
	   	$file_content = str_replace('{$Affiliates_Regnow_Product_ID}',$regnow_rows[1],$file_content);
	   	$regnow_rows = explode('-',$regnow_rows[1]);
	   	$file_content = str_replace('{$Affiliates_Regnow_Vendor_ID}',$regnow_rows[0],$file_content);
		$file_content = str_replace('{$Program_Name}',$rows[0]['product_name'],$file_content);
		$file_content = str_replace('{$Program_Version}',$rows[0]['version_name'],$file_content);
		$file_content = str_replace('{$Program_Cost_Dollars}',empty($rows[0]['price'])?'0.00':$rows[0]['price'],$file_content);
		$file_content = str_replace('{$Program_OS_Support}',strip_tags($support_intro_arr[0]),$file_content);
		$file_content = str_replace('{$Program_Change_Info}',$rows[0]['whatisnew_content'],$file_content);
		$file_content = str_replace('{$Application_Icon_URL}',$rows[0]['product_icon_max'],$file_content);
	    $file_content = str_replace('{$Primary_Download_URL}',$rows[0]['download_url'],$file_content);
	    unset($rows);
		$dates = explode('-',$post_arr['product_pub_date']);//分割日期
		$category_rows = explode('::',$post_arr['product_pdf_category']);
	    $file_content = str_replace('{$Program_Release_Month}',$dates[1],$file_content);
		$file_content = str_replace('{$Program_Release_Day}',$dates[2],$file_content);
		$file_content = str_replace('{$Program_Release_Year}',$dates[0],$file_content);
		$file_content = str_replace('{$Program_Language}',$post_arr['product_language'],$file_content);
		$file_content = str_replace('{$Program_Specific_Category}',$category_rows[0],$file_content);
		$file_content = str_replace('{$Program_Category_Class}',$post_arr['product_pdf_category'],$file_content);
		$file_content = str_replace('{$Program_System_Requirements}',$post_arr['Program_System_Requirements'],$file_content);
		$file_content = str_replace('{$File_Size_Bytes}',$post_arr['File_Size_Bytes'],$file_content);
		$file_content = str_replace('{$File_Size_K}',$post_arr['File_Size_K'],$file_content);
		$file_content = str_replace('{$File_Size_MB}',$post_arr['File_Size_MB'],$file_content);
		$file_content = str_replace('{$Has_Expire_Info}',$post_arr['Has_Expire_Info'],$file_content);
		$file_content = str_replace('{$Expire_Count}',$post_arr['Expire_Count'],$file_content);
		$file_content = str_replace('{$Expire_Based_On}',$post_arr['Expire_Based_On'],$file_content);
		$file_content = str_replace('{$Expire_Other_Info}',$post_arr['Expire_Other_Info'],$file_content);
		$file_content = str_replace('{$Keywords}',$post_arr['Keywords'],$file_content);
		$file_content = str_replace('{$Char_Desc_45}',$post_arr['Char_Desc_45'],$file_content);
		$file_content = str_replace('{$Char_Desc_80}',$post_arr['Char_Desc_80'],$file_content);
		$file_content = str_replace('{$Char_Desc_250}',$post_arr['Char_Desc_250'],$file_content);
		$file_content = str_replace('{$Char_Desc_450}',$post_arr['Char_Desc_450'],$file_content);
		$file_content = str_replace('{$Char_Desc_2000}',$post_arr['Char_Desc_2000'],$file_content);
		$file_content = str_replace('{$Affiliates_URL}',$post_arr['Affiliates_URL'],$file_content);
		$file_content = str_replace('{$Application_Screenshot_URL}',$post_arr['Application_Screenshot_URL'],$file_content);
		$file_content = str_replace('{$Program_Type}',$post_arr['Program_Type'],$file_content);
		return $file_content;
		
	}
	
	/**
	* @循环创建目录
	* @param  NULL
	* @return  string
	*/
	function MakeDir1($dirurl)
	{
		$dir = split('[\/\\]',$dirurl);
		$strDir = "";
		for($i = 0; $i < count($dir); $i++)
		{
			$strDir .= $dir[$i]."/";
			if($strDir != "/")
			{
				if(!@is_dir($strDir))
				{
					@mkdir($strDir,0775);
					@chmod($strDir,0775);
				}
			}
		}
	}
}
$action    = $_REQUEST['action']; 
$product_pad  = new ProductPad;
if(method_exists($product_pad, $action)) 
{
	$product_pad->$action();
}else{
	$product_pad->index();
}
	
?>
